<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="真实姓名" prop="name">
                <el-input
                    v-model="queryParams.name"
                    placeholder="请输入真实姓名"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="银行名称" prop="bankName">
                <el-input
                    v-model="queryParams.bankName"
                    placeholder="请输入银行名称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="账号" prop="accountNo">
                <el-input
                    v-model="queryParams.accountNo"
                    placeholder="请输入银行名称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="状态" prop="status">
               <el-select v-model="queryParams.status" placeholder="状态" clearable style="width: 200px">
                  <el-option
                     v-for="dict in dict.type.commiswithd_status"
                     :key="dict.value"
                     :label="dict.label"
                     :value="dict.value"
                  />
               </el-select>
            </el-form-item>
            <el-form-item label="提现类型" prop="type">
               <el-select v-model="queryParams.type" placeholder="提现类型" clearable style="width: 200px">
                  <el-option
                     v-for="dict in dict.type.commiswithd_type"
                     :key="dict.value"
                     :label="dict.label"
                     :value="dict.value"
                  />
               </el-select>
            </el-form-item>
            <el-form-item label="创建时间" prop="dateRange">
              <el-date-picker
                v-model="queryParams.dateRange"
                type="datetimerange"
                range-separator="-"
                start-placeholder="开始日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width:333px;"
                :default-time="['00:00:00','23:59:59']"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>

            <el-form-item >
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="真实姓名" align="center" prop="name"/>
            <el-table-column label="账号" align="center" prop="accountNo"/>
            <el-table-column label="银行名称" align="center" prop="bankName"/>
            <el-table-column label="开户地址" align="center" prop="bankAddress"/>
            <el-table-column label="提现金额" align="center" prop="price"/>
            <el-table-column label="提现手续费" align="center" prop="feePrice"/>
            <el-table-column label="当前总佣金" align="center" prop="totalPrice"/>
            <el-table-column label="提现类型" align="center" prop="type">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.commiswithd_type" :value="row.type" />
                </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.commiswithd_status" :value="row.status" />
                </template>
            </el-table-column>
            <el-table-column label="审核驳回原因" align="center" prop="auditReason" show-overflow-tooltip/>
            <el-table-column label="审核时间" align="center" prop="auditTime"/>
            <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>
            <el-table-column label="创建时间" align="center" prop="createTime"/>
            <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
              <template slot-scope="{row}">
                <el-button
                   type="text"
                   @click="byapplying(row, 1)"
                   v-hasPermi="['trade:personalBrokerageWithdraw:audit']"
                   v-if="row.status === 0">通过申请
                </el-button>
                <el-button
                   type="text"
                   @click="handReject(row, -1)"
                   v-hasPermi="['trade:personalBrokerageWithdraw:audit']"
                   v-if="row.status === 0">驳回申请
                </el-button>
              </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 审核弹框 -->
        <el-dialog :title="title" :visible.sync="openExamine" width="60%" append-to-body>
          <div class="diy-mx-8">
            <!---审核表单-->
            <div class="diy-mt-4">
              <el-form ref="form" :model="form" :rules="rules" label-width="88px">
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="驳回原因" prop="auditReason">
                      <el-input v-model="form.auditReason" :rows="6" type="textarea" placeholder="请输入驳回原因"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 认</el-button>
            <el-button @click="openExamine = false">关 闭</el-button>
          </div>
        </el-dialog>
    </div>
</template>

<script >
import {personalBrokerageWithdrawList,getPersonalBrokerageWithdraw,approve,reject,} from "@/api/everyonePile/commiswithd";

export default {
  name: 'Commiswithd',
  dicts: ['commiswithd_status','commiswithd_type'],
  components: {  },
  data() {
    return {
      form: {},// 表单参数
      // 表单校验
      rules: {
        auditReason: [
          { required: true, message: "驳回原因不能为空", trigger: "change" }
        ],
      },
      // 弹出层标题
      title: "",
      //审核弹出层
      openExamine: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
        dateRange:[],
      },
      // 总条数
      total: 0,
      list:[],//页面数据
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    submitForm(){//驳回申请提交
      this.$refs["form"].validate(valid => {
        if (valid) {
          reject(this.form).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.getList();
            this.openExamine = false;
          });
        }
      });
    },
    handReject(e){//驳回申请
      this.title = '驳回申请'
      this.openExamine = true
      this.form = {id:e.id}
    },
    byapplying(e){//通过申请
      this.$modal.confirm('是否确认通过申请该数据项？').then(function() {
        return approve({id:e.id});
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      personalBrokerageWithdrawList(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {// 查询参数
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryRef");
      this.handleQuery();
    },
  }
}
</script>
